package top.oauth2.sms.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Service;
import top.oauth2.sms.enums.SmsTypeEnum;
import top.oauth2.sms.exception.BaseException;
import top.oauth2.sms.service.SelectSmsService;
import top.oauth2.sms.service.SmsService;

/**
 * @author xphu
 * @version 1.0
 * @date 2021/9/16 12:06
 */
@Service
public class SelectSmsServiceImpl extends SelectSmsService {
    @Autowired
    private ApplicationContext applicationContext;
    /**
     * 验证短信验证码
     *
     * @param phone      手机号
     * @param code       验证码
     * @param templateId 短信模板id
     * @param typeEnum   短信提供商类型枚举
     * @author xphu
     * @date: 2021/9/16 10:11
     */
    @Override
    public boolean sendSmsMsg(String phone, String code, String templateId, SmsTypeEnum typeEnum) throws BaseException {
        if (typeEnum == null){
            typeEnum = SmsTypeEnum.SMS_TYPE_TX;
        }
        SmsService smsService = (SmsService) applicationContext.getBean(typeEnum.serviceName);
        return smsService.sendSmsCode(phone, code, templateId);
    }
}
